﻿package com.manyiaby.view.viewutils;

import com.manyiaby.model.workartmodel.WorkArtDataList;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yx on 2017/11/8.
 * 将List集合按大小分割
 */

public class DivisionListUtil {

    /**
     * 按指定大小，分隔集合，将集合按规定个数分为n个部分 *  * @param list * @param len * @return
     */
    public static List<List<WorkArtDataList>> splitList(List<WorkArtDataList> list, int len) {
        if (list == null || list.isEmpty() || len < 1) {
            return null;
        }
        List<List<WorkArtDataList>> result = new ArrayList<List<WorkArtDataList>>();
        int size = list.size();
        int count = (size + len - 1) / len;
        for (int i = 0; i < count; i++) {
            List<WorkArtDataList> subList = list.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
            result.add(subList);
        }
        return result;
    }



   /**
     * 获取最高，最低值
     *
     * @param data
     */
    private int[] getMaxMin(List<Integer> data) {
        int[] m = new int[2];
        //默认最大值和最小值都是第一个
        int max = data.get(0);
        int min = data.get(0);
        for (int i = 1; i < data.size(); i++) {
            //拿默认的第一个数值和后边所有的数据一一比较，如果大于或小于就直接赋值。
            if (max < data.get(i)) {
                max = data.get(i);
            }
            if (min > data.get(i)) {
                min = data.get(i);
            }
        }
        m[0] = max;
        m[1] = min;
        //System.out.println("最大值" + max + "最小值" + min);
        Log.i("aaa", "最大值" + max + "最小值" + min);
        return m;
    }




}
